package w3_c2_queue;

import w3_c1_array.Array;

public class ArrayQueue <E> implements Queue<E>{

    Array <E> array ;

    public ArrayQueue(int capacity) {
        array = new Array<>(capacity);
    }

    public ArrayQueue(){
        this(10);
    }

    public int getCapacity(){
        return array.getCapacity();
    }
    @Override
    public int getSize() {
       return array.getSize();
    }

    @Override
    public boolean isEmpty() {
        return array.isEmpty();
    }

    @Override
    public void enqueue(E e) {
        array.addLast(e);
    }

    @Override
    public E dequeue() {
        return array.removeFirst();
    }

    @Override
    public E getFront() {
        return array.getFirst();
    }

    @Override
    public String toString() {
        StringBuilder res = new StringBuilder();
        res.append("Queue: [");
        for (int i = 0; i < array.getSize(); i++) {
            res.append(array.get(i));
            if(i != array.getSize() -1)
                res.append(", ");
        }
        res.append("] rare");
        return res.toString();
    }

    public static void main(String[] args) {
        ArrayQueue <Integer> queue = new ArrayQueue<>();
        int N = 1000000;
        for (int i = 0; i < N; i++) {
            long start = System.nanoTime();
            queue.enqueue(i);
            long end = System.nanoTime();
            System.out.println("enqueue time: " + (end - start) /1e3 + " us");
            if(i % 3 == 2){
                start = System.nanoTime();
                queue.dequeue();
                end = System.nanoTime();
                System.out.println("dequeue time: " + (end - start) /1e3 + " us");
            }
        }
    }
}
